package com.xzy.springboot.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.xzy.springboot.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
//设置默认降级方法(默认降级方法不能有参数)
//@DefaultProperties(defaultFallback = "deffallback")
public class OrderController {

    @Value("${server.port}")
    String port;

    @Autowired
    private PaymentService paymentService;

    @GetMapping("/order/getok/{id}")
    String PaymentOk(@PathVariable("id") Integer id){
        String s = paymentService.PaymentOk(id)+"port:  "+port;
        log.info(s);
        return s;

    }


    //未指明则用默认降级方法

    @GetMapping("/order/getout/{id}")
    String PaymentTimeout(@PathVariable("id") Integer id){
      //int a = 1/0;
        String s = paymentService.PaymentTimeout(id)+"port:  "+port;
        log.info(s);
        return s;
    }


    String deffallback(){

        return "线程池:  "+Thread.currentThread().getName()+"     消费者侧服务降级;       ";
    }


}
